home *** CD-ROM | disk | FTP | other *** search
- #include <WindowMgr.h>
- #include <MenuMgr.h>
- #include <EventMgr.h>
- #include "Skel defines.h"
- #include "Skel globals.h"
-
- #include <MemoryMgr.h>
-
- /*
-
- SetUps for handling memory
- ########################## SetUpMemory ############################
- This very important set of initializations can be left out of the
- first versions of a program. We are making sure that memory is laid
- out as we desire, with adequate protection against running out of
- memory, bad handles, etc.
- */
-
- setupmemory () {
-
-
- #define maxStackSize 8192 /* max size of stack; the heap gets the
- rest */
-
- typedef long *lomemptr; /* a pointer to low memory locations */
-
- lomemptr nilptr; /* will have value NIL */
- lomemptr stackbaseptr; /* points to current stack base */
-
- /*
- If you define a GrowZone function to Handle bad memory problems,
- you should define it at the top level (not nested), and set it
- here. We don't.
- */
- /* SetGrowZone(&mygrowzone);
- */
- /*
- Place a longint -1 (an odd and therefore illegal address) in the
- memory location that would be referenced by an accidentally-NULL
- Handle, so the error will be caught at Handle-reference time (as
- an Address error, ID=02) instead of later on.
- */
-
- nilptr = 0l;
- *nilptr = (long)-1;
-
- /*
- If you needed to use an Application heap limit other than the
- default (which allows 8K for the stack), you'd set it here,
- possible using this technique of explicitly specifying the maximum
- stack size and allocating the rest to the heap. Should be
- independent of memory size. */
-
- stackbaseptr = (lomemptr) 0x908;
- /* CurStackBase from Tlasm/sysequ.text */
- SetApplLimit ((Ptr) (*stackbaseptr - maxStackSize));
-
- /*
- Expand the application heap Zone to its maximum size, without
- purging any purgeable resources. This saves memory compactions
- and heap expansions later.
- */
-
- MaxApplZone ();
-
- /*
- get plenty of master pointers now; if we let the Memory Manager
- Allocate them as needed, they'd form non-relocatable islands in
- the heap.
- */
-
- MoreMasters ();
- MoreMasters ();
- MoreMasters ();
-
- /*
- Here you might install bulwarks against running out of memory
- unexpectedly. One such (cheesy) technique is to here Allocate
- a large Handle, call it "CheeseBuf", which you can de-Allocate
- in your GrowZone function, when you must obtain more memory to
- avoid a crash. While de-allocated, the program could prevent
- the user from doing anything requiring memory, and tell him he
- must discard windows or some such memory freeing action. Each
- time he does so, the program can try to re-Allocate CheeseBuf;
- if it succeeds, the user can go on doing memory-eating operations.
- */
-
- } /* SetUpMemory */
-
- /*
- ############################ SetUpMenus #############################
-
- Once-only initialization for menus
- We read in all menus from the resource file, and install them,
- and all desk accessories (drivers).
-
- */
-
-
-
- setupmenus () {
- int i;
-
- for (i = 2; i <= lastmenu; i++) /* get all my menus in */
- mymenus[i] = GetMenu (i); /* use the fact that our
- menu ID's start at 1 */
- mymenus[applemenu] = NewMenu(applemenu, "\p\024" );
- AddResMenu (mymenus[applemenu], 'DRVR');
- /* pull in all desk accessories */
- for (i = 1; i <= lastmenu; i++) InsertMenu (mymenus[i], 0);
- DrawMenuBar ();
- }
-
- /*
- body of SetUp
- Once-only initialization for Skel
- ############################ SetUp ##############################
-
- Initialize our program. It seems best to Handle:
- Memory inits first, ToolBox inits second, then the program variables'
- inits. Note that the order of inits is important; see "Using the
- Dialog Manager" in the Dialog Mgr section.
-
- */
-
- setup () {
- /*
- The following function is not declared in <win.h>, although
- that is where you would expect it. - WHJ 3/10/85
- */
-
- Rect screenrect;
-
- setupmemory (); /* init memory layout and protection */
-
- /* init QuickDraw, and everybody else */
-
- InitGraf(&thePort);
- InitFonts();
- FlushEvents( everyEvent, 0 );
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
-
- /*
- Init the system event mask, in case the previous program left
- it in a bad state. If you set it non-standard here, FIX IT
- BEFORE EXITING, because the Finder (1.1g) does NOT set it.
- */
- /* SetEventMask (everyEvent - keyUpMask);*//* standard setting */
- /*
- Get the port which is the whole screen, to use when deactivating
- our window. This prevents the current GrafPort pointer from
- ever dangling.
- */
- GetWMgrPort (&screenport); /* get whole screen port that window mgr
- uses */
- SetPort (screenport); /* and start off with it */
-
- /*
- get window: use wRecord storage. Port is set to that of the
- new window.
- GetNewWindow posts an update event for the new window,
- so it will be redrawn right away.
- */
- mywindow = GetNewWindow (windowid, &wrecord, (long) - 1);
- /* -1 => frontmost window */
-
- /* set up dragRect; we can drag the window within it */
- screenrect.top = screenBits.bounds.top;
- /* don't assume screen size */
- screenrect.left = screenBits.bounds.left;
- screenrect.bottom = screenBits.bounds.bottom;
- screenrect.right = screenBits.bounds.right;
-
- /*
- set drag Rect to avoid menu bar, and keep at least 4 pixels
- on screen
- */
- SetRect (&dragrect, 4, 24, screenrect.right - 4, screenrect.bottom - 4);
-
- /* set up GrowRect, for limits on window growing */
- SetRect (&growrect, 48, 14, screenrect.right - 7, screenrect.bottom - 7);
-
- /* pull in and set up our menus */
- setupmenus ();
-
- }
-
-